package cn.xuqiudong.console.module.timer.schedule.signin.handler;

import cn.xuqiudong.common.base.craw.BaseCrawl;
import cn.xuqiudong.console.module.timer.schedule.signin.enums.SignInFrequencyEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.DayOfWeek;
import java.time.LocalDate;

/**
 * 描述:
 * base sign in
 *
 * @author Vic.xu
 * @since 2024-06-24 11:45
 */
public abstract class AbstractSignInHandler extends BaseCrawl {
    public static final Logger LOGGER = LoggerFactory.getLogger(AbstractSignInHandler.class);

    /**
     * 判断是否可以执行
     */
    public static boolean executedJudge(SignInFrequencyEnum frequency) {
        boolean result = false;
        switch (frequency) {
            case DAILY:
                result = true;
                break;
            case WEEKLY:
                //周一才执行
                DayOfWeek dayOfWeek = LocalDate.now().getDayOfWeek();
                result = DayOfWeek.MONDAY == dayOfWeek;
                break;
            case MONTHLY:
                //每月一号
                int dayOfMonth = LocalDate.now().getDayOfMonth();
                result = 1 == dayOfMonth;
                break;
            default:
                break;
        }
        return result;
    }

    @Override
    protected int getTimeout() {
        return 20000;
    }
}
